$(document).ready(
    function(){
        
        var UI = {};
        (function (UI) {
            
            UI.start = function(){
                $.when(Actions.userOverviewFetch({action : "test"})).then(
                    function(data){
                        var html = "";
                        var row = null;
                        for(var i = 0; i<data.length; i++){
                            row = data[i];
                            var accountName = "Unknown";
                            if(row.account_type === "0"){
                                accountName = "Private";
                            } else if(row.account_type === "1"){
                                accountName = "Business";
                            }
                            html += "<tr id='row-" + (i + 1) + "'>";
                            html += "<td>" + row.username + "</td>";
                            html += "<td>" + row.email + "</td>";
                            html += "<td>" + row.first_name + "</td>";
                            html += "<td>" + row.last_name + "</td>";
                            html += "<td>" + row.password + "</td>";
                            html += "<td>" + row.status_name + "</td>";
                            html += "<td>" + accountName + "</td>";
                            html += "</tr>";
                        }
                        $("#new-user-grid").append(html);
                    }
                );
            };
            
        }(UI));
        var Helpers = {};
        (function (Helpers) {
            
            
            
        }(Helpers));
        
        var Actions = {};
        (function (Actions) {
            
            Actions.userOverviewFetch = function(args) {
                var dfd = new $.Deferred();
                $.ajax({
                    type: "GET",
                    url: "../resources/helpers/userOverviewFetch.php",
                    data: args,
                    cache: false,
                    success: function(data){
                        data = JSON.parse(data);
                        dfd.resolve(data);
                    }
                });
                return dfd.promise();
            };
            
        }(Actions));
        
        var Controller = {};
        (function (Controller) {
            
            Controller.init= function(){
                
            };
            
        }(Controller));	
        
        UI.start();
        Controller.init();
    }
);